package com.cskaoyan.service;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketFeedbackExample;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.Arrays;
import java.util.List;

/**
 * @author Ramsey
 * @date 2023年05月28日 17:30
 */
public class AdminFeedbackServiceimpl implements AdminFeedbackService {

    @Override
    public CommonData query(Integer page, Integer limit, String sort, String order) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketFeedbackMapper mapper = sqlSession.getMapper(MarketFeedbackMapper.class);
        PageHelper.startPage(page, limit);
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        marketFeedbackExample.setOrderByClause(sort + " " + order);
        List<MarketFeedback> marketFeedbacks = mapper.selectByExample(marketFeedbackExample);
        PageInfo<MarketFeedback> marketFeedbackPageInfo = new PageInfo<>(marketFeedbacks);
        sqlSession.close();
        return CommonData.data(marketFeedbackPageInfo);
    }

    @Override
    public List<MarketFeedback> selectByUsername(String username) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketFeedbackMapper mapper = sqlSession.getMapper(MarketFeedbackMapper.class);
        List<MarketFeedback> marketFeedbackList = mapper.selectByUsername(username);
        for (MarketFeedback marketFeedback : marketFeedbackList) {
            System.out.println(marketFeedback);
        }
        sqlSession.close();
        return marketFeedbackList;
    }

    @Override
    public List<MarketFeedback> selectByid(Integer feedbackId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        MarketFeedbackMapper mapper = sqlSession.getMapper(MarketFeedbackMapper.class);
        MarketFeedback marketFeedback = mapper.selectByPrimaryKey(feedbackId);
        List<MarketFeedback> marketFeedbackList = Arrays.asList(marketFeedback);
        for (MarketFeedback feedback : marketFeedbackList) {
            System.out.println(feedback);
        }
        sqlSession.close();
        return marketFeedbackList;
    }
}
